package com.ldx.java_chatroom.config;

import com.ldx.java_chatroom.controller.WebSocketController;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
//    private TestWebSocket webSocket;
    @Resource
    private WebSocketController webSocketController;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketController, "/webSocketMessage").
                //t通过这个方法可以将http session的attribute 给websocket session
                addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
